home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / FinderGrok / Grok / Source / CBasicApp.cp next >
Text File  |  2000-06-23  |  4KB  |  165 lines

  1. // ===========================================================================
  2. //    CBasicApp.cp                 ©1994-2000 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //    This file contains the starter code for a basic PowerPlant project
  5.  
  6. using namespace std;
  7.  
  8.  
  9. #include "CBasicApp.h"
  10.  
  11. #include <LGrowZone.h>
  12. #include <PP_Messages.h>
  13. #include <PP_Resources.h>
  14. #include <UDrawingState.h>
  15. #include <UMemoryMgr.h>
  16. #include <URegistrar.h>
  17.  
  18. #include <LWindow.h>
  19. #include <LCaption.h>
  20.  
  21. #include "CCWDisplayLine.h"
  22.  
  23.     // Constant declarations
  24. const ResIDT    PPob_SampleWindow            = 128;
  25.  
  26.  
  27. // ===========================================================================
  28. //    • main
  29. // ===========================================================================
  30.  
  31. int main()
  32. {                            
  33.         // Set Debugging options
  34.     SetDebugThrow_(debugAction_Alert);
  35.     SetDebugSignal_(debugAction_Alert);
  36.  
  37.         // Initialize Memory Manager. Parameter is the number of
  38.         // master pointer blocks to allocate
  39.     InitializeHeap(3);
  40.     
  41.         // Initialize standard Toolbox managers
  42.     UQDGlobals::InitializeToolbox(&qd);
  43.     
  44.         // Install a GrowZone to catch low-memory situations    
  45.     new LGrowZone(20000);
  46.  
  47.         // Create the application object and run
  48.     CBasicApp    theApp;
  49.     theApp.Run();
  50.     
  51.     return 0;
  52. }
  53.  
  54.  
  55. // ---------------------------------------------------------------------------
  56. //    • CBasicApp                                        [public]
  57. // ---------------------------------------------------------------------------
  58. //    Application object constructor
  59.  
  60. CBasicApp::CBasicApp()
  61. {
  62.     RegisterClasses();
  63. }
  64.  
  65.  
  66. // ---------------------------------------------------------------------------
  67. //    • ~CBasicApp                                    [public, virtual]
  68. // ---------------------------------------------------------------------------
  69. //    Application object destructor
  70.  
  71. CBasicApp::~CBasicApp()
  72. {
  73.     // Nothing
  74. }
  75.  
  76.  
  77. // ---------------------------------------------------------------------------
  78. //    • StartUp                                        [protected, virtual]
  79. // ---------------------------------------------------------------------------
  80. //    Perform an action in response to the Open Application AppleEvent.
  81. //    Here, issue the New command to open a window.
  82.  
  83. void
  84. CBasicApp::StartUp()
  85. {
  86.     CCWDisplayLine*    theDisplay = new CCWDisplayLine("Str255.cp", 1);
  87.     theDisplay->Display();
  88.     ObeyCommand(cmd_Quit, 0);
  89. //    ObeyCommand(cmd_New, nil);
  90. }
  91.  
  92.  
  93. // ---------------------------------------------------------------------------
  94. //    • ObeyCommand                                    [public, virtual]
  95. // ---------------------------------------------------------------------------
  96. //    Respond to Commands. Returns true if the Command was handled, false if not.
  97.  
  98. Boolean
  99. CBasicApp::ObeyCommand(
  100.     CommandT    inCommand,
  101.     void*        ioParam)
  102. {
  103.     Boolean        cmdHandled = true;    // Assume we'll handle the command
  104.  
  105.     switch (inCommand) {
  106.  
  107.         case cmd_New: {
  108.             LWindow* theWindow = LWindow::CreateWindow(PPob_SampleWindow, this);
  109.             ThrowIfNil_(theWindow);
  110.  
  111.             theWindow->Show();
  112.             break;
  113.         }
  114.  
  115.         default: {
  116.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  117.             break;
  118.         }
  119.     }
  120.     
  121.     return cmdHandled;
  122. }
  123.  
  124.  
  125. // ---------------------------------------------------------------------------
  126. //    • FindCommandStatus                                [public, virtual]
  127. // ---------------------------------------------------------------------------
  128. //    Determine the status of a Command for the purposes of menu updating.
  129.  
  130. void
  131. CBasicApp::FindCommandStatus(
  132.     CommandT    inCommand,
  133.     Boolean&    outEnabled,
  134.     Boolean&    outUsesMark,
  135.     UInt16&        outMark,
  136.     Str255        outName)
  137. {
  138.     switch (inCommand) {
  139.  
  140.         case cmd_New: {
  141.             outEnabled = true;
  142.             break;
  143.         }
  144.  
  145.         default: {
  146.             LApplication::FindCommandStatus(inCommand, outEnabled,
  147.                                             outUsesMark, outMark, outName);
  148.             break;
  149.         }
  150.     }
  151. }
  152.  
  153.  
  154. // ---------------------------------------------------------------------------
  155. //    • RegisterClasses                                [protected]
  156. // ---------------------------------------------------------------------------
  157. //    To reduce clutter within the Application object's constructor, class
  158. //    registrations appear here in this seperate function for ease of use.
  159.  
  160. void
  161. CBasicApp::RegisterClasses()
  162. {
  163.     RegisterClass_(LWindow);
  164.     RegisterClass_(LCaption);
  165. }